<template>
  <div class="search">
    <f-form ref="form" :action="api.drugs" :form-key="this.formItem.drugsId">
      <f-form-item label="药品名称" name="drugsName" :value="formItem.drugsName" :required="true"/>
      <f-form-item label="规格名称" name="drugsSpec" :value="formItem.drugsSpec" :required="true"/>
      <f-form-item label="规格单位" type="select" name="drugsUnit" :value="formItem.drugsUnit" :required="true" :data="drugsUnitData"/>
      <f-form-item label="默认销售价" type="number" name="drugsPrice" :value="formItem.drugsPrice" :precision="4"/>
      <f-form-item label="全局结算价" type="number" name="settlePrice" :value="formItem.settlePrice" :precision="2"/>
      <f-form-item label="无批号成本价" type="number" name="costPrice" :value="formItem.costPrice" :precision="2"/>
      <f-form-item label="底价计算方式" type="radio"  name="floorPriceType" :data="api.drugs.floorPriceType" :value="formItem.floorPriceType"/>
      <f-form-item label="是否自营" type="switch" name="ownerState" :value="formItem.ownerState"/>
      <f-form-item label="商品描述" type="textarea" name="drugsDesc" :value="formItem.drugsDesc"/>
    </f-form>
  </div>
</template>
<script>
  import api from './js/api'

  export default {
    name: 'drugsForm',
    props: {},
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        companyAutoLoad: false,
        supplierAutoLoad: false,
        drugsUnitData: [{ label: '盒', value: '盒' }, { label: '支', value: '支' }, { label: '盒', value: '盒' }, { label: '瓶', value: '瓶' },{ label: '袋', value: '袋' }],
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          drugsId: '',
          drugsName: '',
          drugsSpec: '',
          drugsUnit: null,
          supplierId: null,
          companyId: '',
          organizationId: '',
          ownerState: '',
          drugsDesc: '',
          drugsPrice: 1,
          settlePrice: 1,
          drugsState: ''
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.drugsId) {
          let params = {
            drugsId: data.drugsId
          }
          this.refs['form'].getDetails(params, (data) => {
            //this.$refs['company'].initData()
            this.$refs['supplier'].initData()
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      organizationChange(value) {
        this.$refs['company'].initData({ organizationId: value })
      },
      companyChange(value) {
        this.$refs['supplier'].initData({ companyId: value })
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({}, callback)
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
